<?php
/*
 * @ControllerAnnotation(title="校区管理")
 */

namespace app\crm\controller\product;

use app\common\controller\CrmController;
use app\common\service\BaseService;
use app\crm\traits\Curd;

class Course extends CrmController
{
    protected $validate = 'product\Course';
    protected $model = 'BaseCourse';

    use Curd;

    public function initialize()
    {
        parent::initialize();
        if( in_array($this->request->action(),['add','edit','index']) ){
            $this->assign('campusList', BaseService::getCampusList());// 校区
            $this->assign('majorList', BaseService::getMajorList());  // 专业
        }
    }

    /**
     * @NodeAnotation(title="列表")
     */    
    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model::with('major,campus')
                ->where($where)
                ->count();
            $list = $this->model::with('major,campus')
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select();
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }
    

}